package org.yty.travelagencyredis.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.yty.travelagencyredis.model.Entity.Result;
import org.yty.travelagencyredis.model.Entity.SignUp;
import org.yty.travelagencyredis.model.VO.SignUpQueryByTourGroupIdVO;
import org.yty.travelagencyredis.model.VO.SignUpQueryByTravellerIdVO;
import org.yty.travelagencyredis.service.SignUpService;

@RestController
@RequestMapping("/sign-up")
@RequiredArgsConstructor
public class SignUpController {
    private final SignUpService signUpService;

    @GetMapping("/getTravellerListByTourGroupId/{tourGroupId}")
    public Result<SignUpQueryByTourGroupIdVO> getTravellerListByTourGroupId(@PathVariable Long tourGroupId){
        SignUpQueryByTourGroupIdVO result = this.signUpService.getTravellerListByTourGroupId(tourGroupId);
        if (result == null){
            return Result.error("暂无数据");
        }
        return Result.ok(result);
    }

    @GetMapping("/getTourGroupListByTravellerId/{travellerId}")
    public Result<SignUpQueryByTravellerIdVO> getTourGroupListByTravellerId(@PathVariable Long travellerId){
        SignUpQueryByTravellerIdVO result = this.signUpService.getTourGroupListByTravellerId(travellerId);
        if (result == null){
            return Result.error("暂无数据");
        }
        return Result.ok(result);
    }
    @DeleteMapping("/{tourGroupId}/{travellerId}")
    public Result<Void> deleteByTourGroupIdAndTravellerId(@PathVariable Long tourGroupId, @PathVariable Long travellerId){
        this.signUpService.deleteByTourGroupIdAndTravellerId(tourGroupId, travellerId);
        return Result.ok();
    }

    @PostMapping
    public Result<Void> save(@RequestBody SignUp signUp){
        boolean success = this.signUpService.save(signUp);
        if (!success){
            return Result.error("保存失败");
        }
        return Result.ok();
    }

    @PutMapping
    public Result<Void> update(@RequestBody SignUp signUp){
        boolean success = this.signUpService.update(signUp);
        if (!success){
            return Result.error("更新失败");
        }
        return Result.ok();
    }


}
